<template>
  <el-container>
    <Navigation></Navigation>
    <HeaderBar></HeaderBar>
    <div id="details">
      <!-- 头部 -->
      <div class="page-header">
        <div class="title">
          <p>{{ productDetails.product_name }}</p>
          <!--          <div class="list">-->
          <!--            <ul>-->
          <!--              <li>-->
          <!--                <router-link to>概述</router-link>-->
          <!--              </li>-->
          <!--              <li>-->
          <!--                <router-link to>参数</router-link>-->
          <!--              </li>-->
          <!--              <li>-->
          <!--                <router-link to>用户评价</router-link>-->
          <!--              </li>-->
          <!--            </ul>-->
          <!--          </div>-->
        </div>
      </div>
      <!-- 头部END -->

      <!-- 主要内容 -->
      <div class="main">
        <!-- 左侧商品轮播图 -->
        <div class="block">
          <!--          <el-carousel height="560px" v-if="productPicture.length>1">-->
          <!--            <el-carousel-item v-for="item in productPicture" :key="item.id">-->
          <!--              <img style="height:560px;" :src="$target + item.product_picture" :alt="item.intro"/>-->
          <!--            </el-carousel-item>-->
          <!--          </el-carousel>-->

          <div v-if="productPicture.length===1">
            <img
                style="height:450px;"
                :src="$target + productPicture[0].product_picture"
                :alt="productPicture[0].intro"
            />
          </div>
        </div>
        <!-- 左侧商品轮播图END -->

        <!-- 右侧内容区 -->
        <div class="content">
          <el-input style="width: 360px" v-model="bankNumber" placeholder="请输入银行卡号"></el-input>
          <FileUpload :msg="this.msg" :projectId="productID" :type=0 :limit=4></FileUpload>
          <el-button type="primary" style="margin-left: 110px;margin-top: 20px;width: 120px" @click="submitApply">完成申报
          </el-button>
          <!-- 右侧内容区END -->
        </div>
      </div>
    </div>
    <!-- 主要内容END -->
    <el-footer>
      <FooterBar></FooterBar>
    </el-footer>
  </el-container>
</template>

<script>
import {mapGetters} from "vuex";
import Navigation from "@/components/FrontComponents/Navigation";
import HeaderBar from "@/components/FrontComponents/HeaderBar";
import FooterBar from "@/components/FrontComponents/FooterBar";
import FileUpload from "@/components/FileUpload";

export default {
  name: 'Upload',
  components: {
    FileUpload,
    HeaderBar,
    Navigation,
    FooterBar
  },
  data() {
    return {
      msg: "请上传申报文件",
      dis: false, // 控制“加入购物车按钮是否可用”
      productID: "", // 商品id
      file_data: "",
      bankNumber: "",
      productDetails: "", // 商品详细信息
      productPicture: "", // 商品图片
    }
  },
  // 通过路由获取商品id
  created() {
    if (this.$route.query.productID !== undefined) {
      this.productID = this.$route.query.productID;
    }
  },
  watch: {
    // 监听商品id的变化，请求后端获取商品数据
    productID: function (val) {
      this.getDetails(val);
      this.getDetailsPicture(val);
    }
  },
  methods: {
    ...mapGetters(["getUser"]),
    // 获取商品详细信息
    getDetails(val) {
      this.$axios
          .post("/home/getDetails", {
            product_id: val
          })
          .then(res => {
            this.productDetails = res.data.data;
          })
          .catch(err => {
            return Promise.reject(err);
          });
    },
    // 获取商品图片
    getDetailsPicture(val) {
      this.$axios
          .post("/home/getDetailsPicture", {
            product_id: val
          })
          .then(res => {
            this.productPicture = res.data.data;
          })
          .catch(err => {
            return Promise.reject(err);
          });
    },
    submitApply() {
      if (this.bankNumber === "") {
        this.$message.error("银行卡密码不可为空");
      } else {
        this.$axios.post("/apply/submit",{
          productId: parseInt(this.productID),
          bankNumber: this.bankNumber,
          userId: this.$store.getters.getUser.id
            }
        ).then(res => {
          if (res.data.code === 200) {
            this.$message.success("申报成功，等待审核")
            this.$router.push("/")
          }
          else{
            this.$message.error(res.data.message)
          }
        })
      }
    }
  }
};
</script>

<style scoped>

#details .page-header {
  height: 64px;
  margin-top: 0px;
  z-index: 4;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  -webkit-box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.07);
  box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.07);
}

#details .page-header .title {
  width: 1225px;
  height: 64px;
  line-height: 64px;
  font-size: 18px;
  font-weight: 400;
  color: #212121;
  margin: 0 auto;
}

#details .page-header .title p {
  margin-top: 0px;
  float: left;
}

#details .page-header .title .list {
  height: 64px;
  float: right;
}

#details .page-header .title .list li {
  float: left;
  margin-left: 20px;
}

#details .page-header .title .list li a {
  font-size: 14px;
  color: #616161;
}

#details .page-header .title .list li a:hover {
  font-size: 14px;
  color: #ff6700;
}

/* 头部CSS END */

/* 主要内容CSS */
#details .main {
  width: 1225px;
  height: 560px;
  padding-top: 30px;
  margin: 0 auto;
}

#details .main .block {
  float: left;
  width: 450px;
  height: 450px;
}

#details .el-carousel .el-carousel__indicator .el-carousel__button {
  background-color: rgba(163, 163, 163, 0.8);
}

#details .main .content {
  float: left;
  margin-left: 25px;
  width: 640px;
}

#details .main .content .name {
  height: 30px;
  line-height: 30px;
  font-size: 24px;
  font-weight: normal;
  color: #212121;
}

#details .main .content .intro {
  color: #b0b0b0;
  padding-top: 10px;
}

#details .main .content .store {
  color: #ff6700;
  padding-top: 10px;
}

#details .main .content .price {
  display: block;
  font-size: 18px;
  color: #ff6700;
  border-bottom: 1px solid #e0e0e0;
  padding: 25px 0 25px;
}

#details .main .content .price .del {
  font-size: 14px;
  margin-left: 10px;
  color: #b0b0b0;
  text-decoration: line-through;
}

#details .main .content .pro-list {
  background: #f9f9fa;
  padding: 30px 60px;
  margin: 50px 0 50px;
}

#details .main .content .pro-list span {
  line-height: 30px;
  color: #616161;
}

#details .main .content .pro-list .pro-price {
  float: right;
}

#details .main .content .pro-list .pro-price .pro-del {
  margin-left: 10px;
  text-decoration: line-through;
}

#details .main .content .pro-list .price-sum {
  color: #ff6700;
  font-size: 24px;
  padding-top: 20px;
}

#details .main .content .button {
  height: 55px;
  margin: 10px 0 20px 0;
}

#details .main .content .button .el-button {
  float: left;
  height: 55px;
  font-size: 16px;
  color: #fff;
  border: none;
  text-align: center;
}

#details .main .content .button .shop-cart {
  width: 340px;
  background-color: #ff6700;
}

#details .main .content .button .shop-cart:hover {
  background-color: #f25807;
}

#details .main .content .button .like {
  width: 260px;
  margin-left: 40px;
  background-color: #b0b0b0;
}

#details .main .content .button .like:hover {
  background-color: #757575;
}

#details .main .content .pro-policy li {
  float: left;
  margin-right: 20px;
  color: #b0b0b0;
}

/* 主要内容CSS END */
</style>